package com.wc.codeforces.思维.Left_and_Right_Houses;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2024/6/22 21:07
 * @description https://codeforces.com/problemset/problem/1945/C
 */
public class Main {
    /**
     * 思路：
     * 计数，计道路前0的个数,1的个数,总的0的个数, 1的个数
     * 注意：求|n / 2 - i| n / 2 不取整
     */
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int N = 300010;
    static char[] s;
    static int n;

    public static void main(String[] args) {
        int T = sc.nextInt();
        while (T-- > 0) {
            n = sc.nextInt();
            // x 表示 0 的个数, y 表示 1 的个数
            int x = 0, y = 0;
            s = (" " + sc.next()).toCharArray();
            for (int i = 1; i <= n; i++) {
                if (s[i] == '0') x++;
                else y++;
            }
            int xx = 0, yy = 0;
            int res = N;
            for (int i = 1; i <= n + 1; i++) {
                if (xx >= i / 2 && (y - yy) >= (n - i + 1 + 1) / 2) {
                    if (Math.abs(1.0 * n / 2 - res) > Math.abs(1.0 * n / 2 - (i - 1))) {
                        res = i - 1;
                    } else if (Math.abs(1.0 * n / 2 - res) == Math.abs(1.0 * n / 2 - (i - 1))) {
                        res = Math.min(res, i - 1);
                    }
                }
                if (i == n + 1) break;
                if (s[i] == '0') xx++;
                else yy++;
            }
            out.println(res);
        }
        out.flush();
    }
}


class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}